package com.yan01.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author yyh
 * @create 2020-08-18 11:00
 */
@Controller
@RequestMapping(path="/user")
public class RequestMappingTest {
    /**
     * 基本操作
     * @return
     */
    @RequestMapping("/Test01")
    public String antTest01(){
        System.out.println("antTest01...");
        return "success";
    }

    /**
     * ?匹配一个字符,0个多个都不行;
     * 		模糊和精确多个匹配情况下，精确优先
     *
     * @return
     */
    @RequestMapping("/Test0?")
    public String antTest02(){
        System.out.println("antTest02...");
        return "success";
    }

    /**
     *   *匹配任意多个字符
     * @return
     */
    @RequestMapping("/Test0*")
    public String antTest03(){
        System.out.println("antTest03...");
        return "success";
    }

    /**
     *  *：匹配一层路径
     * @return
     */
    @RequestMapping("/a/*/Test01")
    public String antTest04(){
        System.out.println("antTest04...");
        return "success";
    }

    @RequestMapping("/a/**/Test01")
    public String antTest05(){
        System.out.println("antTest05...");
        return "success";
    }

    //路径上可以有占位符：  占位符 语法就是可以在任意路径的地方写一个{变量名}
    //   /user/admin    /user/leifengyang
    // 路径上的占位符只能占一层路径
    @RequestMapping("/user/{id}")
    public String pathVariableTest(@PathVariable("id")String id){
        System.out.println("路径上的占位符的值"+id);
        return "success";
    }

    @RequestMapping(value="/handle02",method= RequestMethod.POST)
    public String handle02(){
        System.out.println("handle02...");
        return "success";
    }

    /**
     *
     * @return
     */
    @RequestMapping(value="/handle03",params={"username!=123","pwd","!age"})
    public String handle03(){
        System.out.println("handle03....");
        return "success";
    }

    /**
     * User-Agent：浏览器信息；
     * 让火狐能访问，让谷歌不能访问
     *
     * 谷歌：
     * User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
     * 火狐;
     * User-Agent	Mozilla/5.0 (Windows NT 6.3; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0
     * @return
     *
     */
    @RequestMapping(value="/handle04",headers={"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36"})
    public String handle04(){
        System.out.println("handle04....");
        return "success";
    }
}
